#ifndef __LINKTREE_H_
#define __LINKTREE_H_
#include <iostream>
#include "DynamicArray.h"

using ElementType = std::string;
class TreeNode
{
public:
    TreeNode(const ElementType &element);
    void Contact(TreeNode *parents);    // 将结点绑定为另一个结点的孩子
    void Didcontact(TreeNode *parents); // 解绑
    void show(TreeNode *node, int depth);

    static void FreeNode(TreeNode *node);
    static TreeNode *FindNode(TreeNode *node, const ElementType &element);
    static void FindNode(TreeNode *node, const ElementType &element, DynamicArray &a);

    static int GetNodeHeight(TreeNode *node);
    TreeNode *Getparents();
    std::string &GetData();
    void SetData(const ElementType &element);

private:
    ElementType data;     // 数据域
    TreeNode *parents;    // 双亲指针
    TreeNode *child;      // 孩子指针
    TreeNode *nextSbling; // 下一个兄弟指
};

class LinkTree
{
public:
    LinkTree();
    LinkTree(const ElementType &element);
    TreeNode *GetRoot();
    void show();
    ~LinkTree();
    DynamicArray FindByElement(const ElementType &element);
    int GetTreeHeight();
    std::string GetNodepath(TreeNode *node);

private:
    TreeNode *root; // 根节点
};

#endif